<template>
  <div class="app-content">
    <el-table :data="dkTableData" style="width: 100%" class="table">
      <el-table-column prop="id" label="id" width="80" align="center" sortable="custom" />
      <el-table-column prop="nickname" label="昵称" min-width="100" align="center" />
      <el-table-column prop="external_userid" label="外部客户ID" min-width="100" align="center">
        <template #default="scope">
          <el-tag size="small" effect="dark" class="cursor-pointer" type="info" @click="handleClipboard(scope.row.external_userid, $event)">
            复制
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="create_time" label="日期" width="200">
        <template #default="scope">
          <div>
            <div>
              <p class="text-gray-500 mb-5px">创建日期：</p>
              <p>{{ scope.row.create_time }}</p>
            </div>
            <div>
              <p class="text-gray-500 mb-5px">更新日期：</p>
              <p>{{ scope.row.update_time }}</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <!--
        <el-table-column label="操作" width="80">
          <template #default="scope">
            <el-button size="small" type="primary" @click="openCreateForm(scope.row.id)">编辑</el-button>
          </template>
        </el-table-column>
        -->
    </el-table>
    <div class="m-10px p-10px">
      <el-pagination
        background
        layout="total,prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="pageSize"
        @current-change="fetchList"
      />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import clipboard from '@/utils/clipboard'
import { getList } from '@/api/platform/work_wechat/kf_user'
import { getPlaid } from '@/utils/auth'

defineOptions({
  name: 'UserList'
})

// 响应式数据
const page = ref(1)
const pageSize = ref(10)
const total = ref(0)
const dkTableData = ref([])
const searchData = ref({
  plaid: getPlaid()
})

// 方法
const handleClipboard = (text, event) => {
  clipboard(text, event)
}

const fetchList = (newPage) => {
  if (newPage !== undefined) {
    page.value = newPage
  }

  getList(page.value, pageSize.value, searchData.value).then((res) => {
    dkTableData.value = res.data
    total.value = parseInt(res.msg)
  })
}

// 初始化
onMounted(() => {
  fetchList(page.value)
})
</script>

<style scoped></style>
